#include <asm.h>

.global C_SYMBOL(DrawXMajorLine)
.global C_SYMBOL(DrawYMajorLine)

C_SYMBOL(DrawVerticalLine):
    STMFD	SP!, {R4-R12,LR}
Start1:
End1:
	LDMFD	SP!, {R4-R12,PC}




C_SYMBOL(DrawHorizontalLine):
    STMFD	SP!, {R4-R12,LR}
Start2:
End2:
	LDMFD	SP!, {R4-R12,PC}




C_SYMBOL(DrawXMajorLine):

inc = -0x28
color = -0x24
D_Y16 = -0x20
S_Y16 = -0x1C
x = -0x18
nDstPitch= -0x14
pDst= -0x10

    STMFD	SP!, {R4-R12,LR}
    SUB     SP, SP, #0x4C
Start3:

    LDR     R12, [R0,#0x0]

    LDR     R5, [R0,#0x4]

    LDR     R6, [R0,#0x8]

    LDR     R10, [R0,#0xC]

    LDR     R7, [R0,#0x10]

    LDR     R8, [R0,#0x14]

    LDR     R11, [R0,#0x18]

    LDR     R9, [R0,#0x1C]

    TMCRR   wR13 , R9, R9
    WUNPCKELUB wR13, wR13

    LDR	   R1, =0x00000008
    TMCRR   wR15 , R1, R1

    LDR     R1, = 0x00FF00FF
    TMCRR   wR14, R1, R1

    WZERO   wR12

    LDR     LR, =0xFFFF

XMajorLoop:

    MOV     R2, R7, ASR #16
    MLA     R4, R2, R5, R12
    AND     R3, R7, LR
    ADD     R4, R4, R6, LSL# 2
    WLDRW   wR0, [R4]
    ADD     R9, R4, R5
    WLDRW   wR1, [R9]
    MOV     R3, R3, LSR #8
    TBCSTH  wR2, R3             // wR2 = a
    WUNPCKELUB wR0, wR0
    WMULUL  wR0, wR0, wR2
    WSUBH   wR3, wR14, wR2      // wR3 = 255 -a
    WSRLH   wR0, wR0, wR15
    WMULUL  wR4, wR13, wR3
    WUNPCKELUB wR1, wR1
    WSRLH   wR4, wR4, wR15
    WMULUL  wR5, wR13, wR2
    WADDH   wR0, wR0, wR4
    WMULUL  wR1, wR1, wR3
    WSRLH   wR5, wR5, wR15
    WSRLH   wR1, wR1, wR15
    WADDH   wR1, wR1, wR5
    WPACKHUS wR0, wR0, wR12
    WPACKHUS wR1, wR1, wR12
    SUBS    R10, R10, #1
    WSTRW   wR0, [R4]
    WSTRW   wR1, [R9]
    ADD     R7, R7, R8
    ADD     R6, R6, R11
    BGT     XMajorLoop

End3:
    ADD     SP, SP, #0x4C
	LDMFD	SP!, {R4-R12,PC}



_DrawYMajorLine:

    STMFD	SP!, {R4-R12,LR}
    SUB     SP, SP, #0x4C
Start4:

    LDR     R12, [R0,#0x0]      //pDst

    LDR     R5, [R0,#0x4]       //nPitch

    LDR     R6, [R0,#0x8]       //startP

    LDR     R10, [R0,#0xC]      //deltaD

    LDR     R7, [R0,#0x10]      //s16

    LDR     R8, [R0,#0x14]      //d16

    LDR     R11, [R0,#0x18]     //inc

    LDR     R9, [R0,#0x1C]      //color

    TMCRR   wR13 , R9, R9
    WUNPCKELUB wR13, wR13

    LDR	   R1, =0x00000008
    TMCRR   wR15 , R1, R1

    LDR     R1, = 0x00FF00FF
    TMCRR   wR14, R1, R1

    WZERO   wR12

    LDR     LR, =0xFFFF

YMajorLoop:

    MOV     R2, R7, ASR #16
    MLA     R4, R6, R5, R12
    AND     R3, R7, LR
    ADD     R4, R4, R2, LSL# 2
    WLDRW   wR0, [R4]
//    ADD     R9, R4, R5
    WLDRW   wR1, [R4, #4]
    MOV     R3, R3, LSR #8
    TBCSTH  wR2, R3             // wR2 = a
    WUNPCKELUB wR0, wR0
    WMULUL  wR0, wR0, wR2
    WSUBH   wR3, wR14, wR2      // wR3 = 255 -a
    WSRLH   wR0, wR0, wR15
    WMULUL  wR4, wR13, wR3
    WUNPCKELUB wR1, wR1
    WSRLH   wR4, wR4, wR15
    WMULUL  wR5, wR13, wR2
    WADDH   wR0, wR0, wR4
    WMULUL  wR1, wR1, wR3
    WSRLH   wR5, wR5, wR15
    WSRLH   wR1, wR1, wR15
    WADDH   wR1, wR1, wR5
    WPACKHUS wR0, wR0, wR12
    WPACKHUS wR1, wR1, wR12
    SUBS    R10, R10, #1
    WSTRW   wR0, [R4]
    WSTRW   wR1, [R4, #4]
    ADD     R7, R7, R8
    ADD     R6, R6, R11
    BGT     YMajorLoop

End4:
    ADD     SP, SP, #0x4C
	LDMFD	SP!, {R4-R12,PC}
